package com.rhem.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.Widget;

public class HeaderPanel extends Composite {
	@UiField
	MyMenuBar menuBar;
	
	@UiField
	ImageAnchor home;
	
	@UiField
	SpanElement hometxt;

	private static HeaderPanelUiBinder uiBinder = GWT
			.create(HeaderPanelUiBinder.class);

	interface HeaderPanelUiBinder extends UiBinder<Widget, HeaderPanel> {
	}
	
	private RhemSolConstants constants = GWT.create(RhemSolConstants.class);


	public HeaderPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		
		menuBar.addStyleName("csti-MenuBar");
		SafeHtmlBuilder builder = new SafeHtmlBuilder();
		
		builder.appendHtmlConstant("<div>").appendEscaped(constants.productos()).appendHtmlConstant("</div>");
		MenuItem servicios = menuBar.addItem(new MenuItem(builder.toSafeHtml(), new MenuCommand()));
		servicios.setCommand(new MenuCommand("servicios",servicios));
		menuBar.addSeparator();
		
		builder = new SafeHtmlBuilder();
		builder.appendHtmlConstant("<div>").appendEscaped(constants.clientes()).appendHtmlConstant("</div>");
		MenuItem comprar = menuBar.addItem(new MenuItem(builder.toSafeHtml(), new MenuCommand()));
		comprar.setCommand(new MenuCommand("comprar",comprar));
		menuBar.addSeparator();
		
		builder = new SafeHtmlBuilder();
		builder.appendHtmlConstant("<div>").appendEscaped(constants.noticias()).appendHtmlConstant("</div>");
		MenuItem noticias = menuBar.addItem(new MenuItem(builder.toSafeHtml(), new MenuCommand()));
		noticias.setCommand(new MenuCommand("noticias",noticias));
		menuBar.addSeparator();		
		
		builder = new SafeHtmlBuilder();
		builder.appendHtmlConstant("<div>").appendEscaped(constants.contacto()).appendHtmlConstant("</div>");
		MenuItem contactenos = menuBar.addItem(new MenuItem(builder.toSafeHtml(), new MenuCommand()));
		contactenos.setCommand(new MenuCommand("contactenos",contactenos));
		
		home.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {				
				menuBar.removeStyleNameAll("csti-activo");
				History.newItem("home");
			}
		});
		
		hometxt.setInnerText(constants.inicio());
	}

}
